package com.beagle.njddapp.ui.activity.owner;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.beagle.njddapp.R;
import com.beagle.njddapp.base.BaseMvpActivity;
import com.beagle.njddapp.ui.adapter.VpAdapter;
import com.beagle.njddapp.ui.fragment.DIrverOrderFragment;
import com.beagle.njddapp.ui.fragment.OilOrderFragment;
import com.beagle.njddapp.ui.presenter.OrderPresenter;
import com.beagle.njddapp.ui.view.OrderView;
import com.beagle.njddapp.utils.StatusBarUtil;
import com.blankj.utilcode.util.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author hxx
 * @date 2021-03-02 22:31
 * 订单
 */
public class OrderActivity extends BaseMvpActivity<OrderView, OrderPresenter> implements OrderView, ViewPager.OnPageChangeListener {


    @BindView(R.id.commom_title_tv)
    TextView tvTitle;
    @BindView(R.id.common_container)
    RelativeLayout container;
    @BindView(R.id.common_iv_right)
    ImageView ivRight;
    @BindView(R.id.order_oil_tv)
    TextView tvOrderOil;
    @BindView(R.id.view2)
    View view2;
    @BindView(R.id.order_dirver_tv)
    TextView tvOrderDirver;
    @BindView(R.id.view3)
    View view3;
    @BindView(R.id.viewpager)
    ViewPager viewPager;
    private int type = 2, color_blue,color_black;
    private List<Fragment> fragmentList;
    private VpAdapter vpAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_order;
    }

    @Override
    public void init() {
        StatusBarUtil.immersive(this);
        StatusBarUtil.darkMode(this);
        StatusBarUtil.setPaddingSmart(this, container);
        tvTitle.setText("订单管理");
        container.setBackgroundColor(Color.WHITE);
        color_blue = Color.parseColor("#0049FF");
        color_black = Color.parseColor("#0d0d0d");
        fragmentList=new ArrayList<>();
        fragmentList.add(new OilOrderFragment());
        fragmentList.add(new DIrverOrderFragment());
        vpAdapter=new VpAdapter(getSupportFragmentManager(),fragmentList);
        viewPager.setAdapter(vpAdapter);
        viewPager.addOnPageChangeListener(this);
    }

    @Override
    public OrderView getMvpView() {
        return this;
    }

    @Override
    public OrderPresenter createPresenter() {
        return new OrderPresenter();
    }

    @Override
    public void onError(String message) {

    }

    @OnClick({R.id.common_back_iv, R.id.rl_order_work, R.id.rl_order_oil, R.id.rl_order_dirver})
    public void onCLick(View view) {
        switch (view.getId()) {
            case R.id.common_back_iv:
                onBackPressed();
                break;
            case R.id.rl_order_work:
                ToastUtils.showShort("此功能即将开放");
                break;
            case R.id.rl_order_oil:
                if (type == 2) {
                    return;
                }
                type = 2;
                viewPager.setCurrentItem(0);
                break;
            case R.id.rl_order_dirver:
                if (type == 3) {
                    return;
                }
                type = 3;
                viewPager.setCurrentItem(1);
                break;

        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        if (position==0){
            type = 2;
            tvOrderOil.setTextColor(color_blue);
            view2.setBackground(new ColorDrawable(color_blue));
            tvOrderDirver.setTextColor(color_black);
            view3.setBackground(new ColorDrawable(Color.WHITE));
        }else {
            type = 3;
            tvOrderDirver.setTextColor(color_blue);
            view3.setBackground(new ColorDrawable(color_blue));
            tvOrderOil.setTextColor(color_black);
            view2.setBackground(new ColorDrawable(Color.WHITE));
        }

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
